<template>
    <div class="goods">
      <el-row>
        <el-col :span="24">
        <el-breadcrumb separator-class="el-icon-arrow-right">
            <el-breadcrumb-item :to="{ path: '/' }">首页</el-breadcrumb-item>
            <el-breadcrumb-item>商品管理</el-breadcrumb-item>
            <el-breadcrumb-item>商品列表</el-breadcrumb-item>
        </el-breadcrumb>
        </el-col>
      </el-row>
      <el-row>
        <el-button type="success" plain @click="addGoods()">添加商品</el-button>     
      </el-row>
      <el-table
        :data="tableData"
        style="width: 100%" border>
        <el-table-column  prop="goods_id" label="#" width="50">

        </el-table-column>
        <el-table-column prop="goods_name" label="商品名称" width="600">

        </el-table-column>
        <el-table-column prop="goods_price" label="商品价格" width="100">

        </el-table-column>
        <el-table-column prop="goods_number" label="商品数量" width="100">

        </el-table-column>
        <el-table-column label="操作" width="200">
        <template slot-scope="scope">
            <el-button
            size="mini" class="el-icon-edit" type="primary"
            @click="handleEdit(scope.$index, scope.row)"></el-button>
            <el-button
            size="mini"
            type="danger" class="el-icon-delete"
            @click="handleDelete(scope.$index, scope.row)"></el-button>
            <el-button
            size="mini"
            class="el-icon-check" type="info"
            @click="handleDelete(scope.$index, scope.row)"></el-button>
        </template>
        </el-table-column>
    </el-table>
    <div class="page">
    <el-pagination
      @size-change="handleSizeChange"
      @current-change="handleCurrentChange"
      :current-page="currentPage4"
      :page-sizes="[1,10, 50,100]"
      :page-size="1"
      layout="total, sizes, prev, pager, next, jumper"
      :total="total">
    </el-pagination>
    </div>
    </div>
</template>

<script>
import {getGoodsList} from '@/api/index.js'

export default {
     data() {
      return {
        total:0,
        pagenum:1,
        pagesize:10,
        currentPage4:1,
        tableData: [{
          id: 1,
          name: '王小虎',
          address: '上海市普陀区金沙江路 1518 弄'
        }, {
          id: 2,
          name: '王小虎',
          address: '上海市普陀区金沙江路 1517 弄'
        }, {
          id: 3,
          name: '王小虎',
          address: '上海市普陀区金沙江路 1519 弄'
        }, {
          id: 4,
          name: '王小虎',
          address: '上海市普陀区金沙江路 1516 弄'
        }]
      }
    },
    created:function(){
        this.initList()
    },
    methods: {
      initList:function(){
          getGoodsList({params:{pagenum:this.pagenum,pagesize:this.pagesize}}).then(res=>{
              if(res.meta.status == 200){
                  this.tableData = res.data.goods
                  this.total = res.data.total
              }
          })
      },
      //跳转商品添加页
      addGoods:function(){
          this.$router.push({name:'GoodsAdd'})
      },
      handleEdit(index, row) {
        console.log(index, row);
      },
      handleDelete(index, row) {
        console.log(index, row);
      },
      handleSizeChange(val) {
        console.log(`每页 ${val} 条`);
        this.pagesize = val
        this.initList()
      },
      handleCurrentChange(val) {
        console.log(`当前页: ${val}`);
        this.pagenum = val
        this.initList()
      }
    }
}
</script>


<style scoped>
 .goods .page {
    padding: 5px 0;
    background-color: #D3DCE6;
  }
</style>